import Vue from 'vue'
import Router from 'vue-router'

// import Home from '@/views/home/template/Template.vue'
// import Index from '@/views/home/index/Index.vue'
// import MyProject from '@/views/home/project/Myproject.vue'
// import ProjectJoin from '@/views/home/template/Template.vue'
// import Batch from '@/views/home/batch/Batch.vue'
// import BatchSetting from '@/views/home/batch/BatchSetting.vue'
// import Delcare from '@/views/home/declare/Declare.vue'
// import DelcareFill from '@/views/home/declare/DeclareFill.vue'
Vue.use(Router)

// const route = [{
//   home: Home,
//   index: Index,
//   myProject: MyProject,
//   projectJoin: ProjectJoin,
//   batch: Batch,
//   batchSetting: BatchSetting,
//   delcare: Delcare,
//   delcareFill: DelcareFill
// }
// ]
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'sign',
      redirect: '/login',
      component: () => import('@/views/login/template/Template.vue'),
      children: [
        {
          path: '/login',
          name: 'login', //登录
          component: () => import('@/views/login/Login.vue'),
        },
        {
          path: '/forget',
          name: 'forget',
          component: () => import('@/views/login/Forget.vue'),
        }
      ]
    }, {
      path: '/home',
      name: 'home',
      redirect: '/index',
      component: () => import('@/views/home/template/Template.vue'),
      children: [
        {
          path: '/index',
          name: 'index',
          component: () => import('@/views/home/index/Index.vue'),
        },
        {
          path: '/modifyEmail',
          name: 'modifyEmail',
          component: () => import('@/views/home/information/ModifyEmail.vue'),
        },
        {
          path: '/modifyPassword',
          name: 'modifyPassword',
          component: () => import('@/views/home/information/ModifyPassword.vue'),
        },

        {
          path: '/declare',
          name: 'declare',
          component: () => import('@/views/home/declare/Declare.vue'),
        },
        {
          path: '/declareFill',
          name: 'declareFill',
          component: () => import('@/views/home/declare/DeclareFill.vue'),
        },{
          path: '/declareEdit',
          name: 'declareEdit',
          component: () => import('@/views/home/declare/DeclareEdit.vue'),
        },
        {
          path: '/myProject',
          name: 'myProject',
          component: () => import('@/views/home/project/Myproject.vue'),
        },
        {
          path: '/projectJoin',
          name: 'projectJoin',
          component: () => import('@/views/home/project/Projectjoin.vue'),
        },{
          path: '/lookover',
          name: 'lookover',
          component: () => import('@/views/home/project/lookover.vue'),
        },
        {
          path: '/departmentSetting',
          name: 'departmentSetting',
          component: () => import('@/views/home/department/DepartmentSetting.vue'),
        },
        {
          path: '/adminSetting',
          name: 'adminSetting',
          component: () => import('@/views/home/department/AdminSetting.vue'),
        },
        {
          path: '/labelDb',
          name: 'labelDb',
          component: () => import('@/views/home/personnel/LabelDb.vue'),
        },
        {
          path: '/passwordReset',
          name: 'passwordReset',
          component: () => import('@/views/home/personnel/PasswordReset.vue'),
        },
        {
          path: '/expertDb',
          name: 'expertDb',
          component: () => import('@/views/home/personnel/ExpertDb.vue'),
        },
        {
          path: '/batch',
          name: 'batch',
          component: () => import('@/views/home/batch/Batch.vue'),
        },
        {
          path: '/batchCreat',
          name: 'batchCreat',
          component: () => import('@/views/home/batch/BatchCreat.vue'),
        },
		{
		  path: '/batchComplie',
		  name: 'batchComplie',
		  component: () => import('@/views/home/batch/BatchComplie.vue'),
		},
    {
      path: '/batchDepMaxPassNumber',
      name: 'batchDepMaxPassNumber',
      component: () => import('@/views/home/batch/BatchDepMaxPassNumber.vue'),
    },
    {
      path: '/batchDepMaxPassNumber',
      name: 'batchDepMaxPassNumber',
      component: () => import('@/views/home/batch/BatchDepMaxPassNumber.vue'),
    },
    {
      path: '/ExpertSet',
      name: 'ExpertSet',
      component: () => import('@/views/home/batch/ExpertSet.vue'),
    },
      {
        path: '/permissionTransfer',
        name: 'permissionTransfer',
        component: () => import('@/views/home/system/PermissionTransfer.vue'),
      },
		{
		  path: '/depApprovalAudit',
		  name: 'depApprovalAudit',
		  component: () => import('@/views/home/delApprovalAudit/depApprovalAudit.vue'),
		},
    {
      path: '/depProjectAudit',
      name: 'depProjectAudit',
      component: () => import('@/views/home/delApprovalAudit/DepProjectAudit.vue'),
    },
    {
      path: '/depProjectAuditPdf',
      name: 'depProjectAuditPdf',
      component: () => import('@/views/home/delApprovalAudit/depProjectAuditPdf.vue'),
    },
    {
      path: '/depProjectAuditRecord',
      name: 'depProjectAuditRecord',
      component: () => import('@/views/home/delApprovalAudit/depProjectAuditRecord.vue'),
    },
    {
      path: '/uniApprovalAudit',
      name: 'uniApprovalAudit',
      component: () => import('@/views/home/delApprovalAudit/uniApprovalAudit.vue'),
    },{
      path: '/uniProjectAudit',
      name: 'uniProjectAudit',
      component: () => import('@/views/home/delApprovalAudit/uniProjectAudit.vue'),
    }, {
      path: '/uniProjectAuditPdf',
      name: 'uniProjectAuditPdf',
      component: () => import('@/views/home/delApprovalAudit/uniProjectAuditPdf.vue'),
    },{
      path: '/expertApprovalAudit',
      name: 'expertApprovalAudit',
      component: () => import('@/views/home/delApprovalAudit/expertApprovalAudit.vue'),
    },{
      path: '/expertProjectAudit',
      name: 'expertProjectAudit',
      component: () => import('@/views/home/delApprovalAudit/expertProjectAudit.vue'),
    },{
      path: '/expertProjectAuditPdf',
      name: 'expertProjectAuditPdf',
      component: () => import('@/views/home/delApprovalAudit/expertProjectAuditPdf.vue'),
    },{
      path: '/uniSecondProjectAudit',
      name: 'uniSecondProjectAudit',
      component: () => import('@/views/home/delApprovalAudit/uniSecondProjectAudit.vue'),
    },{
      path: '/uniSecondProjectAuditPdf',
      name: 'uniSecondProjectAuditPdf',
      component: () => import('@/views/home/delApprovalAudit/uniSecondProjectAuditPdf.vue'),
    },{
      path: '/metahsse',
      name: 'metahsse',
      component: () => import('@/views/home/phase/phase.vue'),
    },{
      path: '/createPhase',
      name: 'createPhase',
      component: () => import('@/views/home/phase/createPhase.vue'),
    },{
      path: '/editPhase',
      name: 'editPhase',
      component: () => import('@/views/home/phase/editPhase.vue'),
    },{
      path: '/phaseDeclare',
      name: 'phaseDeclare',
      component: () => import('@/views/home/phase/phaseDeclare.vue'),
    },{
      path: '/depPhase',
      name: 'phaseDep',
      component: () => import('@/views/home/phaseAudit/phaseDep.vue'),
    },{
      path: '/phaseDepAudit',
      name: 'phaseDepAudit',
      component: () => import('@/views/home/phaseAudit/phaseDepAudit.vue'),
    },{
      path: '/schPhase',
      name: 'schPhase',
      component: () => import('@/views/home/phaseAudit/phaseSch.vue'),
    },{
      path: '/phaseSchAudit',
      name: 'phaseSchAudit',
      component: () => import('@/views/home/phaseAudit/phaseSchAudit.vue'),
    },{
      path: '/checkPdf',
      name: 'checkPdf',
      component: () => import('@/views/home/phaseAudit/checkPdf.vue'),
    },{
      path: '/schPhase',
      name: 'schPhase',
      component: () => import('@/views/home/phaseAudit/phaseSch.vue'),
    },{
      path: '/phaseSchAudit',
      name: 'phaseSchAudit',
      component: () => import('@/views/home/phaseAudit/phaseSchAudit.vue'),
    },{
      path: '/closing',
      name: 'closing',
      component: () => import('@/views/home/closing/closing.vue'),
    },{
        path:'/closingExpert',
        name:'closingExpert',
        component: () => import('@/views/home/closing/ExpertSet.vue')
      },{
      path: '/closingCreate',
      name: 'closingCreate',
      component: () => import('@/views/home/closing/closingCreate.vue'),
    },{
      path: '/closingEdit',
      name: 'closingEdit',
      component: () => import('@/views/home/closing/closingEdit.vue'),
    },{
      path: '/closingDep',
      name: 'closingDep',
      component: () => import('@/views/home/closingAudit/closingDep.vue'),
    },{
      path: '/closingDepAudit',
      name: 'closingDepAudit',
      component: () => import('@/views/home/closingAudit/closingDepAudit.vue'),
    },{
      path: '/closingSch',
      name: 'closingSch',
      component: () => import('@/views/home/closingAudit/closingSch.vue'),
    },{
      path: '/closingSchAudit',
      name: 'closingSchAudit',
      component: () => import('@/views/home/closingAudit/closingSchAudit.vue'),
    },{
      path: '/closingExp',
      name: 'closingExp',
      component: () => import('@/views/home/closingAudit/closingExp.vue'),
    },{
      path: '/closingSecSchAudit',
      name: 'closingSecSchAudit',
      component: () => import('@/views/home/closingAudit/closingSecSchAudit.vue'),
    },{
      path: '/closingExpAudit',
      name: 'closingExpAudit',
      component: () => import('@/views/home/closingAudit/closingExpAudit.vue'),
    },{
      path: '/postponeCause',
      name: 'postponeCause',
      component: () => import('@/views/home/project/postponeCause.vue'),
    },{
      path: '/delayDepAudit',
      name: 'delayDepAudit',
      component: () => import('@/views/home/delay/delayDepAudit.vue'),
    },{
      path: '/delaySchAudit',
      name: 'delaySchAudit',
      component: () => import('@/views/home/delay/delaySchAudit.vue'),
    },{
      path: '/schProjectRecord',
      name: 'schProjectRecord',
      component: () => import('@/views/home/proRecord/schProjectRecord.vue'),
    },{
      path: '/depProjectRecord',
      name: 'depProjectRecord',
      component: () => import('@/views/home/proRecord/depProjectRecord.vue'),
    }
      ]
    },
    {
      path: '*',
      name: '404',
      component: () => import('@/views/error/error.vue'),
    }
  ],
})


router.beforeEach((to, from, next) => {
  // const isLogin = localStorage.getItem('isLogin'); //获取本地存储的登陆信息
  const isLogin = localStorage.getItem('token'); //获取本地存储的登陆信息
  if (to.name == 'login') { //判断是否进入的login页
    if (isLogin != undefined) {  //判断是否登陆
      next({ name: 'home' });  //已登录，跳转首页（a页面）
    } else {
      next();  //没登录，继续进入login页
    }
  }
  else { //如果进入的非login页
    if (isLogin != undefined) {   //同样判断是否登陆
      next();  //已登录，正常进入
    } else {
      if (to.name == 'initialize' || to.name == "forget")
        next();  //没登录，跳转到login页
      else
        next({ name: 'login' });  //没登录，跳转到login页
    }
  }
});


export default router;


// export const admin = [
//   {
//     path: '/home',
//     name: 'home',
//     redirect: '/index',
//     component: () => import('@/views/home/template/Template.vue'),
//     children: [
//       {
//         path: '/index',
//         name: 'index',
//         component: () => import('@/views/home/index/Index.vue'),
//       },
//       {
//         path: '/myproject',
//         name: 'myproject',
//         component: () => import('@/views/home/project/Myproject.vue'),
//       },
//       {
//         path: '/projectjoin',
//         name: 'projectjoin',
//         component: () => import('@/views/home/project/Projectjoin.vue'),
//       },
//       {
//         path: '/batch',
//         name: 'batch',
//         component: () => import('@/views/home/batch/Batch.vue'),
//       },
//        {
//         path: '/batchSetting',
//         name: 'batchSetting',
//         component: () => import('@/views/home/batch/BatchSetting.vue'),
//       },
//       {
//         path: '/declare',
//         name: 'declare',
//         component: () => import('@/views/home/declare/Declare.vue'),
//       }
//     ]
//   },
//   {
//     path: '*',
//     name: '404',
//     component: () => import('@/views/error/error.vue'),
//   },
// ]
